import sys
from math import ceil
from typing import List
import re
import xlwt


# 长列表分组
def orderByList(lst: List[str], num: int) -> List[List[str]]:
    """

    :rtype: List[List[str]]:
    """
    return list(map(lambda x: lst[x * num:x * num + num], list(range(0, ceil(len(lst) / num)))))


if __name__ == '__main__':
    stateStr = sys.argv[1] # 分析内容
    lists=re.split(r'\s*,\s*',stateStr.strip(" []"))
    interval = int(sys.argv[2]) # 分析间隔
    id = sys.argv[3] # 分析id
    column = round(30 / interval)
    # 新建工作簿
    xls = xlwt.Workbook()
    # 新建sheet
    sht1 = xls.add_sheet('Sheet1')
    res = orderByList(lists, column)
    for row,value in enumerate(res):
        for column,data in enumerate(res[row]):
            sht1.write(row, column, data)
    xls.save('D:/easy-ctba/python/st/'+id+'.xlsx')
    print('D:/easy-ctba/python/st/'+ id + '.xlsx')
